<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
class OrderController extends Controller
{
    
    public function getIndex(Request $request){
        //获取设定的分页一页信息条数
        $count = $request->input('count',10);
        //获取查询条件
        $search = $request -> input('search','');
        //查询数据库  按照姓名查询  并按照获取数字值进行分页
        $data = DB::table('tbl_order')
            ->join("tbl_home_user","tbl_order.uid","=","tbl_home_user.id")
            ->join("tbl_goods","tbl_order.gid","=","tbl_goods.id")
            ->where('ordernumber','like','%'.$search.'%')->paginate($count);
            // dd($data);
        //对$request所有的值和数据库查询的结果$data进行传值
        return view('admin.order.index',['data'=>$data,'request'=>$request->all()]);
    }

    public function getDelete($id){
        $res = DB::table('tbl_order') -> where('id','=',$id) -> delete();
        if($res){
            return redirect('/admin/order/index') -> with('success','删除成功');
        }else{
            return back() -> with('error','删除失败');
        }
    }

    public function getEdit($id){
        $data = DB::table('tbl_order') -> where('id','=',$id) -> first(); 
        return view('/admin/order/edit',['data'=>$data]);
    }

    public function postUpdate(Request $request){
        $arr = $request -> except('_token','id');
        $a=$request->input('id');
        $res = DB::table('tbl_order') ->where('id',$request->input('id')) -> update($arr);  
        if($res){
            return redirect('/admin/order/index') -> with('success','修改成功');
        }else{
            return back();
        }
    }
}
